from random import *
from time import *

class GuessNumberGame:

    def __init__(self, a = 0, b = 100) -> None:
        seed(time())
        self.down = a
        self.up = b
        self.user_guess = 0
        self.number = randint(self.down, self.up)

    def newGame(self) -> None:
        self.number = randint(self.down, self.up)

    def input(self):
        input_hint_text = "请输入数字(" + str(self.down) + "~" + str(self.up) + ")"
        try:
            self.user_guess = eval(input(input_hint_text))
        except NameError:
            self.user_guess = self.down - 1

    def rightQ(self) -> bool:
        if self.number == self.user_guess:
            return True
        return False

    def hint(self) -> None:
        if self.user_guess == self.number:
            print("猜对了，重新开始游戏")
        elif self.user_guess == self.down - 1:
            print("输入内容必须为整数!")
        elif self.user_guess > self.number:
            print("猜大了")
        elif self.user_guess < self.number:
            print("猜小了")
        return

    def _showNumber(self) -> None:
        print(self.number)


game = GuessNumberGame()
while 1:
    game._showNumber()
    game.input()
    game.hint()
    if game.rightQ():
        game.newGame()
